<?php
	session_start();
	$captcha = imagecreatefrompng("comment.png");
	$text_c = "";
	for($i = 0; $i < 4; $i++)
	{
		do
		{
			$tmp    = rand(0, 1000);
			$shatmp = SHA1($tmp);
			$text   = strtoupper(substr($shatmp, rand(1, 20), 1));
		}
		while($text == "0" || $text == "O"); //Tránh số 0 hoặc chữ O
		
		$font = rand(1, 8) . ".ttf";
		$black = imagecolorallocate($captcha, rand(0, 255), rand(0, 255), rand(0, 255));
		imagettftext($captcha, 30, 0, ($i * 40) + 40, 38, $black, $font, $text);
		$text_c .= $text;
	}
	$_SESSION['code_captcha'] = $text_c;
	header("content-type: image/jpeg");
	imagejpeg($captcha);
	imagedestroy();
?>